#include "pieceBrick.h"

CPieceBrick::CPieceBrick() : CMovable()
{
	life = 0;
}

CPieceBrick::	~CPieceBrick()
{

}

void CPieceBrick::Activate(float X,float Y,int Type)
{
	reality = 0;
	life = 1;
	type = Type;
	if(type == 0)
	{
		pos_x = X;
		pos_y = Y-16;
		v_y = -0.3f;
		v_x = -0.05f;
	}
	else if(type == 1)
	{
		pos_x = X+16;
		pos_y = Y-16;
		v_y = -0.3f;
		v_x = 0.05f;	
	}
	else if(type == 2)
	{
		pos_x = X;
		pos_y = Y;
		v_y = -0.2f;
		v_x = -0.05f;		
	}
	else if(type == 3)
	{
		pos_x = X+16;
		pos_y = Y;
		v_y = -0.2f;
		v_x = 0.05f;
	}
	anim = 0;
	type = type%2;
}

void CPieceBrick::RenderFrame(LPDIRECT3DDEVICE9 d3ddv,int t)
{
	DWORD now = GetTickCount();
	Update(t);
	SpriteHandlerSP->Begin(D3DXSPRITE_ALPHABLEND);
	StaticPic->Render(_BackBuffer,pos_x,pos_y,10,8+type%2);
	SpriteHandlerSP->End();
}

void CPieceBrick::Update(int t)
{
	pos_x += v_x*t;
	pos_y += v_y*t;
	v_y += 0.05f;
	if(pos_y >= 255)
	{
		v_y = 0;
		life = 0;
	}
	if(v_y > 0)
		type = 1-type;
}